<!DOCTYPE html>
<html lang="en">
<head>
    <title>Dubbo 测试</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css"/>
    <script src="../../static/layui/layui.all.js"></script>
    <script src="../../static/jquery-3.3.1.min.js"></script>
</head>
<body>
<div style="margin-top: 30px;">

</div>
<div style="width: 100%;">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
        <legend>Dubbo 接口测试</legend>
    </fieldset>
    <form class="layui-form" style="width: 1000px;margin: 0 auto">
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px">接口名</label>
            <div class="layui-input-block" style="margin-left: 160px">
                <input type="text" name="interfaceName" autocomplete="off" placeholder="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px">类型</label>
            <div class="layui-input-block" style="margin-left: 160px">
                <input type="radio" name="resourceType" value="1" title="maven" lay-filter="resourceType" checked>
                <input type="radio" name="resourceType" value="2" title="jar" lay-filter="resourceType">
            </div>
        </div>

        <div class="layui-form-item" id="maven">
            <label class="layui-form-label"  style="width: 120px">maven依赖</label>
            <div class="layui-input-block" style="margin-left: 160px">
                <textarea name="mavenContent" placeholder="" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item" id="jar" style="display: none;">
            <label class="layui-form-label" style="width: 120px">选择jar包路径</label>
            <div class="layui-input-block" style="margin-left: 160px">
                <div class="layui-form-item">
                    <label class="layui-form-label">jar1</label>
                    <div class="layui-input-block">
                        <input type="text" name="jarPath1" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">jar2</label>
                    <div class="layui-input-block">
                        <input type="text" name="jarPath2" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">jar3</label>
                    <div class="layui-input-block">
                        <input type="text" name="jarPath3" autocomplete="off" placeholder="" class="layui-input">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            </div>
        </div>
    </form>
</div>
<script>
    var interfaceData = {};
    var layerResult = null;
    var _layer = null;
    var param = {};
    layui.use(['form', 'layedit'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
        ;
        _layer = layer;

        form.on('radio(resourceType)',function (data) {
            var val = data.value;
            var hide = function () {
                $("#maven").hide();
                $("#jar").hide();
            };
            hide();
            if(val == "1"){
                $("#maven").show();
            }else if(val == "2"){
                $("#jar").show();
            }else if(val == "3"){
                $("#class").show();
            }
        });


        //监听提交
        form.on('submit(demo1)', function (data) {
            var $p = data.field;
            $p.jarPath = ($p.jarPath1 || "")+","+($p.jarPath2 || "")+","+($p.jarPath3 || "");
            param = $p;
            loadJar();
            return false;
        });
        form.render();
    });

    function loadJar() {
        $.ajax({
            url: "/consumer/list",
            type: "post",
            data: JSON.stringify(param),
            contentType: "application/json",
            dataType: "json",
            success: function (data) {
                interfaceData = data;
                openResult();
            },
            error:function (XmlHttpRequest,options,exc) {
                console.log(exc);
                console.log(XmlHttpRequest);
            }
        });
    }

    function openResult() {
        if(layerResult != null){
            return;
        }
        layerResult = layer.open({
            type: 2,
            title: interfaceData.interfaceName,
            content:"/view/result",
            area: ['100%', '100%'],
            maxmin: true,
            skin: 'layui-layer-rim', //加上边框
            closeBtn:1,
            success:function (layero, index) {

            },
            cancel:function () {
                layerResult = null;
            }
        });
    }

</script>
</body>
</html>